package com.alatus.springAI.Handler;

import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.handler.context.RowWriteHandlerContext;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Row;

public class SkipRowsHandler implements RowWriteHandler {
    private int skip;
    public SkipRowsHandler(int skip) {
        this.skip = skip;
    }

    @Override
    public void beforeRowCreate(RowWriteHandlerContext context) {
        if (skip > 0) {
            --skip;
        }
    }

    @Override
    public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer rowIndex, Integer relativeRowIndex, Boolean isHead) {
        // 如果需要跳过的行数大于0，则不需要创建行
        if (skip > 0) {
            --skip;
        }
    }

    @Override
    public void afterRowCreate(RowWriteHandlerContext context) {
        RowWriteHandler.super.afterRowCreate(context);
    }

    @Override
    public void afterRowDispose(RowWriteHandlerContext context) {
        RowWriteHandler.super.afterRowDispose(context);
    }

    @Override
    public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer relativeRowIndex, Boolean isHead) {
        RowWriteHandler.super.afterRowDispose(writeSheetHolder, writeTableHolder, row, relativeRowIndex, isHead);
    }
}